<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>ReAllocateMemory</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="4">ReAllocateMemory()</font></b></p>
<p><b>Syntax</b></p><blockquote>

*NewMemoryID = <font color="#006666"><b>ReAllocateMemory</b></font>(*MemoryID, Size [, Flags])</blockquote>

</blockquote>
<b>Description</b><br><blockquote>



Resizes the given memory buffer to a new size. The memory may be copied to a new location in the 
process if there is not enough memory available at its current location. 

 

</blockquote><p><b>Parameters</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>*MemoryID</i></td>
<td width="90%"> 
 
The address of the memory area to resize. This value must be the result of a call to 
<a href="allocatememory.html">AllocateMemory()</a> or <a href="reallocatememory.html">ReAllocateMemory()</a>. 
<br>
<br>
If this parameter is <font color="#924B72">#Null</font>, the command acts like <a href="allocatememory.html">AllocateMemory()</a> and allocates 
a new memory area of the given size. 

 

</td></tr>
<tr><td><i>Size</i></td>
<td> 
 
The size in bytes for the resized or allocated buffer. 

 

</td></tr>
<tr><td><i>Flags (optional)</i></td>
<td> 
 
It can be one of the following values: 
 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Memory_NoClear</font>: don't fill the extended memory area with zeros. It can help to have faster allocation if the
                      extended memory is used immediately. If the memory size is reduced, this flag has no effect.
</font></pre>

</td></tr>
</table>
</blockquote><p><b>Return value</b></p><blockquote>



Returns the new address of the memory area if it could be resized. In this case, the old '*MemoryID' address can 
no longer be used. If resizing the memory area failed (because there is not enough memory available), the result 
is zero, and the '*MemoryID' address is still valid with the existing memory area and the old size. 

 

</blockquote><p><b>Remarks</b></p><blockquote>



If the size of the memory area is increased, any new bytes are initially filled with zeros unless the <font color="#924B72">#PB_Memory_NoClear</font> flag is specified. 
<br>
<br>
If the program crashes at this command even though the input seems correct, 
it is usually a result of a memory corruption at an earlier time in the program by writing 
at an area outside of the allocated memory area. 
Such an error can be narrowed down to the real cause using the 
<a href="../reference/ide_debugtools.html">purifier</a> debugger tool. 
<br>
<br>
All remaining allocated memory blocks are automatically freed when the program ends. 

 

</blockquote><p><b>Example</b></p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  *MemoryID =<font color="#006666"> AllocateMemory</font>(1000)
<font color="#006666">  PokeS</font>(*MemoryID, "Store this string")
  <font color="#006666">; do something more with it here...</font>
  <font color="#006666">;</font>
  *NewMemoryID =<font color="#006666"> ReAllocateMemory</font>(*MemoryID, 2000) <font color="#006666">; need more memory</font>
  <b><font color="#006666">If</font></b> *NewMemoryID
    <font color="#006666">; work with *NewMemoryID now with size 2000</font>
    <b><font color="#006666">Debug</font></b> "The old contents are still here:"
    <b><font color="#006666">Debug</font></b> <font color="#006666">PeekS</font>(*NewMemoryID)
    <font color="#006666">;</font>
<font color="#006666">    FreeMemory</font>(*NewMemoryID) 
  <b><font color="#006666">Else</font></b>
    <font color="#006666">; resizing failed, keep working with *MemoryID (size 1000)</font>
    <font color="#006666">;</font>
<font color="#006666">    FreeMemory</font>(*MemoryID)
  <b><font color="#006666">EndIf</font></b>
</font></pre>

</blockquote><p><b>See Also</b></p><blockquote>

<a href="allocatememory.html">AllocateMemory()</a>, <a href="freememory.html">FreeMemory()</a>, <a href="memorysize.html">MemorySize()</a> 

</Blockquote><p><b>Supported OS  </b><Blockquote>All</Blockquote></p><center>&lt;- <a href=pokew.html>PokeW()</a> - <a href=index.html>Memory Index</a>


</body></html>